<template>
  <div class="father-box">
    <el-row>
      <el-col :xs="20" :sm="12" :md="12" :lg="12" :xl="12">
        <h2 class="system-title">健康管理系统</h2>
        <el-form class="login-form">
          <el-input placeholder="请输入用户名" v-model="formData.username" class="input-field"></el-input>
          <el-input placeholder="请输入密码" v-model="formData.password" show-password class="input-field"></el-input>
          <el-button style="width: 100%" type="primary" @click="onSubmit" class="login-button">登录</el-button>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {login} from '@/api'

export default {
  data() {
    return {
      formData: {
        username: '',
        password: '',
      }
    }
  },
  methods: {
    // 提交登录
    onSubmit() {
      console.log(this.formData)
      login(this.formData).then((res) => {
        if (res.data.flag) {
          this.$message.success(res.data.message)
          // 将令牌转到localStorage中
          localStorage.setItem('token', res.data.data)
          // 跳转到主页
          this.$router.push({path: '/'})
        } else {
          this.$message.error(res.data.message)
        }
      })
    }
  }
}
</script>

<style lang="less">
.father-box {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #87CEEB; /* 天蓝色背景 */
  background-image: url(@/assets/bg.jpg);
  background-repeat: no-repeat;
}

.system-title {
  font-family: 'Microsoft YaHei', sans-serif;
  font-size: 36px;
  color: #fdfdfd;
  text-align: center;
  width: 360px;
  margin-bottom: 20px;
  margin-left: 120px;
}

.login-form {
  width: 100%;
  max-width: 500px; /* 增大登录面板宽度 */
  padding: 40px; /* 增大内边距 */
  background: rgba(255, 255, 255, 0.7);
  margin-left: 100px;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.input-field {
  margin-bottom: 25px; /* 增大间距 */
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.login-button {
  margin-top: 25px; /* 增大间距 */
  border-radius: 5px;
  transition: background-color 0.3s ease;

  &:hover {
    background: linear-gradient(90deg, #6a11cb, #2575fc);
  }
}
</style>